﻿Imports System.Web.Security
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration


Public Class Account_Register
    Inherits System.Web.UI.Page

    Protected Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
        'Create ConnectionString and Insert Statement
        Dim connectionString As String = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
        Dim insertSql As String = "INSERT INTO [User] (FirstName,LastName,Username,Password,Email)" & " values (@FirstName,@LastName,@Username,@Password,@Email)"
        'Create SQL connection
        Dim con As New SqlConnection(connectionString)

        'Create SQL Command And Sql Parameters

        Dim cmd As New SqlCommand()
        cmd.Connection = con
        cmd.CommandType = CommandType.Text
        cmd.CommandText = insertSql

        Dim firstName As New SqlParameter("@FirstName", SqlDbType.NChar, 50)
        firstName.Value = txtFirstNameSet.Text.ToString()
        cmd.Parameters.Add(firstName)

        Dim lastName As New SqlParameter("@LastName", SqlDbType.NChar, 50)
        lastName.Value = txtLastNameSet.Text.ToString()
        cmd.Parameters.Add(lastName)

        Dim userName As New SqlParameter("@Username", SqlDbType.NChar, 50)
        userName.Value = txtUsernameSet.Text.ToString()
        cmd.Parameters.Add(userName)

        Dim password As New SqlParameter("@Password", SqlDbType.NChar, 50)
        password.Value = txtPasswordSet.Text.ToString()
        cmd.Parameters.Add(password)

        Dim email As New SqlParameter("@Email", SqlDbType.NChar, 50)
        email.Value = txtEmailSet.Text.ToString()
        cmd.Parameters.Add(email)

        ' Dim gender As New SqlParameter("@Gender", SqlDbType.VarChar, 10)
        ' gender.Value = rdoGender.SelectedItem.ToString()
        ' cmd.Parameters.Add(gender)


        Try
            con.Open()
            cmd.ExecuteNonQuery()
            lblMsg.Text = "User Registration successfull"
        Catch ex As SqlException
            Dim errorMessage As String = "Error in registering user"
            errorMessage += ex.Message

            Throw New Exception(errorMessage)
        Finally
            con.Close()
        End Try
    End Sub

End Class
